#ifndef UV_ERRNO_H_
#define UV_ERRNO_H_

#include <errno.h>
#if EDOM > 0
# define UV_ERR(x) (-(x))
#else
# define UV_ERR(x) (x)
#endif

#define UV_EOF     (-4095)
#define UV_UNKNOWN (-4094)

#define UV_EAI_ADDRFAMILY  (-3000)
#define UV_EAI_AGAIN       (-3001)
#define UV_EAI_BADFLAGS    (-3002)
#define UV_EAI_CANCELED    (-3003)
#define UV_EAI_FAIL        (-3004)
#define UV_EAI_FAMILY      (-3005)
#define UV_EAI_MEMORY      (-3006)
#define UV_EAI_NODATA      (-3007)
#define UV_EAI_NONAME      (-3008)
#define UV_EAI_OVERFLOW    (-3009)
#define UV_EAI_SERVICE     (-3010)
#define UV_EAI_SOCKTYPE    (-3011)
#define UV_EAI_BADHINTS    (-3013)
#define UV_EAI_PROTOCOL    (-3014)

/* Only map to the system errno on non-Windows platforms. It's apparently
 * a fairly common practice for Windows programmers to redefine errno codes.
 */
#if defined(E2BIG) && !defined(_WIN32)
# define UV_E2BIG UV_ERR(E2BIG)
#else
# define UV_E2BIG (-4093)
#endif

#if defined(EACCES) && !defined(_WIN32)
# define UV_EACCES UV_ERR(EACCES)
#else
# define UV_EACCES (-4092)
#endif

#if defined(EADDRINUSE) && !defined(_WIN32)
# define UV_EADDRINUSE UV_ERR(EADDRINUSE)
#else
# define UV_EADDRINUSE (-4091)
#endif

#if defined(EADDRNOTAVAIL) && !defined(_WIN32)
# define UV_EADDRNOTAVAIL UV_ERR(EADDRNOTAVAIL)
#else
# define UV_EADDRNOTAVAIL (-4090)
#endif

#if defined(EAFNOSUPPORT) && !defined(_WIN32)
# define UV_EAFNOSUPPORT UV_ERR(EAFNOSUPPORT)
#else
# define UV_EAFNOSUPPORT (-4089)
#endif

#if defined(EAGAIN) && !defined(_WIN32)
# define UV_EAGAIN UV_ERR(EAGAIN)
#else
# define UV_EAGAIN (-4088)
#endif

#if defined(EALREADY) && !defined(_WIN32)
# define UV_EALREADY UV_ERR(EALREADY)
#else
# define UV_EALREADY (-4084)
#endif

#if defined(EBADF) && !defined(_WIN32)
# define UV_EBADF UV_ERR(EBADF)
#else
# define UV_EBADF (-4083)
#endif

#if defined(EBUSY) && !defined(_WIN32)
# define UV_EBUSY UV_ERR(EBUSY)
#else
# define UV_EBUSY (-4082)
#endif

#if defined(ECANCELED) && !defined(_WIN32)
# define UV_ECANCELED UV_ERR(ECANCELED)
#else
# define UV_ECANCELED (-4081)
#endif

#if defined(ECHARSET) && !defined(_WIN32)
# define UV_ECHARSET UV_ERR(ECHARSET)
#else
# define UV_ECHARSET (-4080)
#endif

#if defined(ECONNABORTED) && !defined(_WIN32)
# define UV_ECONNABORTED UV_ERR(ECONNABORTED)
#else
# define UV_ECONNABORTED (-4079)
#endif

#if defined(ECONNREFUSED) && !defined(_WIN32)
# define UV_ECONNREFUSED UV_ERR(ECONNREFUSED)
#else
# define UV_ECONNREFUSED (-4078)
#endif

#if defined(ECONNRESET) && !defined(_WIN32)
# define UV_ECONNRESET UV_ERR(ECONNRESET)
#else
# define UV_ECONNRESET (-4077)
#endif

#if defined(EDESTADDRREQ) && !defined(_WIN32)
# define UV_EDESTADDRREQ UV_ERR(EDESTADDRREQ)
#else
# define UV_EDESTADDRREQ (-4076)
#endif

#if defined(EEXIST) && !defined(_WIN32)
# define UV_EEXIST UV_ERR(EEXIST)
#else
# define UV_EEXIST (-4075)
#endif

#if defined(EFAULT) && !defined(_WIN32)
# define UV_EFAULT UV_ERR(EFAULT)
#else
# define UV_EFAULT (-4074)
#endif

#if defined(EHOSTUNREACH) && !defined(_WIN32)
# define UV_EHOSTUNREACH UV_ERR(EHOSTUNREACH)
#else
# define UV_EHOSTUNREACH (-4073)
#endif

#if defined(EINTR) && !defined(_WIN32)
# define UV_EINTR UV_ERR(EINTR)
#else
# define UV_EINTR (-4072)
#endif

#if defined(EINVAL) && !defined(_WIN32)
# define UV_EINVAL UV_ERR(EINVAL)
#else
# define UV_EINVAL (-4071)
#endif

#if defined(EIO) && !defined(_WIN32)
# define UV_EIO UV_ERR(EIO)
#else
# define UV_EIO (-4070)
#endif

#if defined(EISCONN) && !defined(_WIN32)
# define UV_EISCONN UV_ERR(EISCONN)
#else
# define UV_EISCONN (-4069)
#endif

#if defined(EISDIR) && !defined(_WIN32)
# define UV_EISDIR UV_ERR(EISDIR)
#else
# define UV_EISDIR (-4068)
#endif

#if defined(ELOOP) && !defined(_WIN32)
# define UV_ELOOP UV_ERR(ELOOP)
#else
# define UV_ELOOP (-4067)
#endif

#if defined(EMFILE) && !defined(_WIN32)
# define UV_EMFILE UV_ERR(EMFILE)
#else
# define UV_EMFILE (-4066)
#endif

#if defined(EMSGSIZE) && !defined(_WIN32)
# define UV_EMSGSIZE UV_ERR(EMSGSIZE)
#else
# define UV_EMSGSIZE (-4065)
#endif

#if defined(ENAMETOOLONG) && !defined(_WIN32)
# define UV_ENAMETOOLONG UV_ERR(ENAMETOOLONG)
#else
# define UV_ENAMETOOLONG (-4064)
#endif

#if defined(ENETDOWN) && !defined(_WIN32)
# define UV_ENETDOWN UV_ERR(ENETDOWN)
#else
# define UV_ENETDOWN (-4063)
#endif

#if defined(ENETUNREACH) && !defined(_WIN32)
# define UV_ENETUNREACH UV_ERR(ENETUNREACH)
#else
# define UV_ENETUNREACH (-4062)
#endif

#if defined(ENFILE) && !defined(_WIN32)
# define UV_ENFILE UV_ERR(ENFILE)
#else
# define UV_ENFILE (-4061)
#endif

#if defined(ENOBUFS) && !defined(_WIN32)
# define UV_ENOBUFS UV_ERR(ENOBUFS)
#else
# define UV_ENOBUFS (-4060)
#endif

#if defined(ENODEV) && !defined(_WIN32)
# define UV_ENODEV UV_ERR(ENODEV)
#else
# define UV_ENODEV (-4059)
#endif

#if defined(ENOENT) && !defined(_WIN32)
# define UV_ENOENT UV_ERR(ENOENT)
#else
# define UV_ENOENT (-4058)
#endif

#if defined(ENOMEM) && !defined(_WIN32)
# define UV_ENOMEM UV_ERR(ENOMEM)
#else
# define UV_ENOMEM (-4057)
#endif

#if defined(ENONET) && !defined(_WIN32)
# define UV_ENONET UV_ERR(ENONET)
#else
# define UV_ENONET (-4056)
#endif

#if defined(ENOSPC) && !defined(_WIN32)
# define UV_ENOSPC UV_ERR(ENOSPC)
#else
# define UV_ENOSPC (-4055)
#endif

#if defined(ENOSYS) && !defined(_WIN32)
# define UV_ENOSYS UV_ERR(ENOSYS)
#else
# define UV_ENOSYS (-4054)
#endif

#if defined(ENOTCONN) && !defined(_WIN32)
# define UV_ENOTCONN UV_ERR(ENOTCONN)
#else
# define UV_ENOTCONN (-4053)
#endif

#if defined(ENOTDIR) && !defined(_WIN32)
# define UV_ENOTDIR UV_ERR(ENOTDIR)
#else
# define UV_ENOTDIR (-4052)
#endif

#if defined(ENOTEMPTY) && !defined(_WIN32)
# define UV_ENOTEMPTY UV_ERR(ENOTEMPTY)
#else
# define UV_ENOTEMPTY (-4051)
#endif

#if defined(ENOTSOCK) && !defined(_WIN32)
# define UV_ENOTSOCK UV_ERR(ENOTSOCK)
#else
# define UV_ENOTSOCK (-4050)
#endif

#if defined(ENOTSUP) && !defined(_WIN32)
# define UV_ENOTSUP UV_ERR(ENOTSUP)
#else
# define UV_ENOTSUP (-4049)
#endif

#if defined(EPERM) && !defined(_WIN32)
# define UV_EPERM UV_ERR(EPERM)
#else
# define UV_EPERM (-4048)
#endif

#if defined(EPIPE) && !defined(_WIN32)
# define UV_EPIPE UV_ERR(EPIPE)
#else
# define UV_EPIPE (-4047)
#endif

#if defined(EPROTO) && !defined(_WIN32)
# define UV_EPROTO UV_ERR(EPROTO)
#else
# define UV_EPROTO (-4046)
#endif

#if defined(EPROTONOSUPPORT) && !defined(_WIN32)
# define UV_EPROTONOSUPPORT UV_ERR(EPROTONOSUPPORT)
#else
# define UV_EPROTONOSUPPORT (-4045)
#endif

#if defined(EPROTOTYPE) && !defined(_WIN32)
# define UV_EPROTOTYPE UV_ERR(EPROTOTYPE)
#else
# define UV_EPROTOTYPE (-4044)
#endif

#if defined(EROFS) && !defined(_WIN32)
# define UV_EROFS UV_ERR(EROFS)
#else
# define UV_EROFS (-4043)
#endif

#if defined(ESHUTDOWN) && !defined(_WIN32)
# define UV_ESHUTDOWN UV_ERR(ESHUTDOWN)
#else
# define UV_ESHUTDOWN (-4042)
#endif

#if defined(ESPIPE) && !defined(_WIN32)
# define UV_ESPIPE UV_ERR(ESPIPE)
#else
# define UV_ESPIPE (-4041)
#endif

#if defined(ESRCH) && !defined(_WIN32)
# define UV_ESRCH UV_ERR(ESRCH)
#else
# define UV_ESRCH (-4040)
#endif

#if defined(ETIMEDOUT) && !defined(_WIN32)
# define UV_ETIMEDOUT UV_ERR(ETIMEDOUT)
#else
# define UV_ETIMEDOUT (-4039)
#endif

#if defined(ETXTBSY) && !defined(_WIN32)
# define UV_ETXTBSY UV_ERR(ETXTBSY)
#else
# define UV_ETXTBSY (-4038)
#endif

#if defined(EXDEV) && !defined(_WIN32)
# define UV_EXDEV UV_ERR(EXDEV)
#else
# define UV_EXDEV (-4037)
#endif

#if defined(EFBIG) && !defined(_WIN32)
# define UV_EFBIG UV_ERR(EFBIG)
#else
# define UV_EFBIG (-4036)
#endif

#if defined(ENOPROTOOPT) && !defined(_WIN32)
# define UV_ENOPROTOOPT UV_ERR(ENOPROTOOPT)
#else
# define UV_ENOPROTOOPT (-4035)
#endif

#if defined(ERANGE) && !defined(_WIN32)
# define UV_ERANGE UV_ERR(ERANGE)
#else
# define UV_ERANGE (-4034)
#endif

#if defined(ENXIO) && !defined(_WIN32)
# define UV_ENXIO UV_ERR(ENXIO)
#else
# define UV_ENXIO (-4033)
#endif

#if defined(EMLINK) && !defined(_WIN32)
# define UV_EMLINK UV_ERR(EMLINK)
#else
# define UV_EMLINK (-4032)
#endif

/* EHOSTDOWN is not visible on BSD-like systems when _POSIX_C_SOURCE is
 * defined. Fortunately, its value is always 64 so it's possible albeit
 * icky to hard-code it.
 */
#if defined(EHOSTDOWN) && !defined(_WIN32)
# define UV_EHOSTDOWN UV_ERR(EHOSTDOWN)
#elif defined(_APPLE_) || \
      defined(_DragonFly_) || \
      defined(_FreeBSD_) || \
      defined(_FreeBSD_kernel_) || \
      defined(_NetBSD_) || \
      defined(_OpenBSD_)
# define UV_EHOSTDOWN (-64)
#else
# define UV_EHOSTDOWN (-4031)
#endif

#if defined(EREMOTEIO) && !defined(_WIN32)
# define UV_EREMOTEIO UV_ERR(EREMOTEIO)
#else
# define UV_EREMOTEIO (-4030)
#endif

#if defined(ENOTTY) && !defined(_WIN32)
# define UV_ENOTTY UV_ERR(ENOTTY)
#else
# define UV_ENOTTY (-4029)
#endif

#if defined(EFTYPE) && !defined(_WIN32)
# define UV_EFTYPE UV_ERR(EFTYPE)
#else
# define UV_EFTYPE (-4028)
#endif

#if defined(EILSEQ) && !defined(_WIN32)
# define UV_EILSEQ UV_ERR(EILSEQ)
#else
# define UV_EILSEQ (-4027)
#endif

#if defined(EOVERFLOW) && !defined(_WIN32)
# define UV_EOVERFLOW UV_ERR(EOVERFLOW)
#else
# define UV_EOVERFLOW (-4026)
#endif

#if defined(ESOCKTNOSUPPORT) && !defined(_WIN32)
# define UV_ESOCKTNOSUPPORT UV_ERR(ESOCKTNOSUPPORT)
#else
# define UV_ESOCKTNOSUPPORT (-4025)
#endif

#endif /* UV_ERRNO_H_ */
